package com.lonely.web.controller.inventory;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lonely.common.core.domain.api.R;
import com.lonely.inventory.domain.dto.surplus.*;
import com.lonely.inventory.domain.vo.surplus.SurplusInventoryPageQueryVo;
import com.lonely.inventory.service.ISurplusInventoryService;
import com.lonely.order.domain.vo.order.OrderQuantityInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author : 黄志标
 * @date: 2025/9/19 10:06
 * @description: 尾货库存请求处理器
 */
@RestController
@RequestMapping("/inventoryManager/surplusInventory")
@Api(tags = "库存管理/尾货库存")
public class SurplusInventoryController {

    @Autowired
    private ISurplusInventoryService surplusInventoryService;

    /**
     * 分页查询
     *
     * @param queryDto
     * @return
     */
    @PostMapping("/page")
    @ApiOperation(value = "分页查询")
    public R<Page<SurplusInventoryPageQueryVo>> page(@RequestBody SurplusInventoryPageQueryDto queryDto) {
        return R.data(this.surplusInventoryService.page(queryDto));
    }

    /**
     * 更新尾货库存备注信息
     *
     * @param submitDto
     * @return
     */
    @PostMapping("/submitRemark")
    @SaCheckPermission("inventory:surplusInventory:submitRemark")
    public R<Boolean> submitRemark(@RequestBody @Validated EditSurplusInventoryRemarkDto submitDto) {
        this.surplusInventoryService.submitRemark(submitDto);
        return R.status(true);
    }


    /**
     * 根据尾货库存id获取对应的尺码库存数量信息
     *
     * @param surplusInventoryId
     * @return
     */
    @GetMapping("/getSurplusInventoryStockQuantityInfo/{surplusInventoryId}")
    @ApiOperation(value = "根据尾货库存id获取对应的尺码库存数量信息")
    public R<OrderQuantityInfo> getSurplusInventoryStockQuantityInfo(@PathVariable("surplusInventoryId") Long surplusInventoryId) {
        return R.data(this.surplusInventoryService.getSurplusInventoryStockQuantityInfo(surplusInventoryId));
    }

    /**
     * 更新尾货库存
     *
     * @param submitDto
     * @return
     */
    @PostMapping("/editSurplusInventory")
    @SaCheckPermission("inventory:surplusInventory:editSurplusInventory")
    public R<Boolean> editSurplusInventory(@RequestBody @Validated EditSurplusInventoryDTO submitDto) {
        this.surplusInventoryService.editSurplusInventory(submitDto);
        return R.status(true);
    }


    /**
     * 查询指定订单的尾货库存尺码库存数量初始化信息
     *
     * @param produceOrderId
     * @return
     */
    @GetMapping("/getInitSurplusInventorySizeInfo/{produceOrderId}")
    public R<OrderQuantityInfo> getInitSurplusInventorySizeInfo(@PathVariable("produceOrderId") Long produceOrderId) {
        return R.data(this.surplusInventoryService.getInitSurplusInventorySizeInfo(produceOrderId));
    }


    /**
     * 新增尾货库存
     *
     * @param submitDto
     * @return
     */
    @PostMapping("/addSurplusInventory")
    @SaCheckPermission("inventory:surplusInventory:addSurplusInventory")
    public R<Boolean> addSurplusInventory(@RequestBody @Validated AddSurplusInventoryDTO submitDto) {
        this.surplusInventoryService.addSurplusInventory(submitDto);
        return R.status(true);
    }


    /**
     * 尾货上架
     *
     * @param submitDto
     * @return
     */
    @PostMapping("/surplusStockPutAway")
    public R<Boolean> surplusStockPutAway(@RequestBody @Validated SurplusStockPutAwayDTO submitDto) {
        this.surplusInventoryService.surplusStockPutAway(submitDto);
        return R.data(true);
    }
}
